<template>
    <div>
        <top-bar></top-bar>
        <left-bar :datas='data'></left-bar>
        <div class="main">
            <div class="main-mains">
                <div class="main-content">
                    <div class="main-mains-top">
                        财务管理
                    </div>
                    <div class="main-top-nav">
                        <ul>
                            <router-link to="/withdrawal">
                                <li class="active">提现审批</li>
                            </router-link>
                            <router-link to="/finance">
                                <li>用户管理</li>
                            </router-link>
                            <router-link to="/score">
                                <li>积分管理</li>
                            </router-link>
                        </ul>
                    </div>
                    <div class="withdrawal-total withdrawal-mar">
                        <p>￥{{totalCount}}</p>
                        <p>今日提现总额</p>
                    </div>
                    <div class="screen clear">
                        <div class="fl" @click="screen()">筛选</div>
                    </div>
                    <div class="publicTable toLongTable">
                        <table class="head_table">
                            <tr>
                                <td width="5%">序号</td>
                                <td width="5%">用户账号</td>
                                <td width='12%'>到账银行卡</td>
                                <td width='5%'>提现金额</td>
                                <td width='5%'>手续费</td>
                                <td width='7%'>提现时间</td>
                                <td width='10%'>状态</td>
                                <td width='10%'>操作</td>
                            </tr>
                        </table>
                        <el-scrollbar>
                            <table class="content_table">
                                <tr v-for="(item,index) in listData" :key="index" :class="{active:index%2==1}">
                                    <td width="5%">{{index+1}}</td>
                                    <td width="5%">{{item.mobile}}</td>
                                    <td width='12%'>{{item.bank_account}}</td>
                                    <td width='5%'>{{item.total}}</td>
                                    <td width='5%'>{{item.fee}}</td>
                                    <td width='7%'>{{item.create_time}}</td>
                                    <td width="10%" v-if="item.status == 0">已拒绝</td>
                                    <td width="10%" v-else-if="item.status == 1">未审核</td>
                                    <td width="10%" v-else-if="item.status == 2">已通过</td>
                                    <td width="10%" v-if="item.status == 1" class="operation">
                                        <span class="active" @click="adopt(item.outsn)">通过</span>
                                        <span class="active" @click="refuse(item.outsn)">拒绝</span>
                                    </td>
                                    <td width="10%" v-else>

                                    </td>
                                </tr>
                            </table>
                        </el-scrollbar>
                    </div>
                    <div class="nodataTip" v-if="showNodataTip">
                        <i class="iconfont icon-zanwuneirong"></i>
                        <h5>暂无内容</h5>
                    </div>
                    <div class="orderBotom">
                        <div class="orderBotomRight">
                            <el-pagination @current-change="handleCurrentChange" :page-size="15" layout="total, prev, pager, next" :total='totalnum'>
                            </el-pagination>
                        </div>
                    </div>
                </div>
            </div>
            <div class="system-menban" v-if="search">
            </div>
            <div class="systemPopup" v-if="search">
                <div class="topTitle">
                    <span>筛选</span>
                    <i class="el-icon-close system-icon" @click="hideSystemPopup"></i>
                </div>
                <div class="systemPopup-con">
                    <div class="systemPopup-cons clear">
                        <div class="fl">时间</div>
                        <div class="fl sel">
                            <el-date-picker v-model="time" type="daterange" clearable value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                            </el-date-picker>
                        </div>
                    </div>
                    <div class="systemPopup-cons clear">
                        <div class="fl">手机号码</div>
                        <div class="fl sel">
                            <el-input placeholder="请输入用户名" v-model.trim="userMobile" clearable>
                            </el-input>
                        </div>
                    </div>
                    <div class="systemPopup-cons clear">
                        <div class="fl">状态</div>
                        <div class="fl sel">
                            <el-select clearable v-model="statusType" placeholder="请选择状态">
                                <el-option v-for="item in statusTypes" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                    <div class="systemPopup-btn clear">
                        <div class="fl" @click="searchs()">确认</div>
                        <div class="fl" @click="hideSystemPopup">取消</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>


<script>
import leftBar from "@/components/leftBar";
import topBar from "@/components/topBar";
import finance from "@/api/finance";
export default {
  components: {
    leftBar,
    topBar
  },
  data() {
    return {
      data: "finance",
      pages: 1,
      listData: [],
      totalnum: 0,
      showNodataTip: false,
      search: false,
      time: [],
      userName: "",
      userMobile: "",
      statusType: "",
      statusTypes: [
        {
          value: "1",
          label: "未审核"
        },
        {
          value: "2",
          label: "通过"
        },
        {
          value: "0",
          label: "拒绝"
        }
      ],
      totalCount: ""
    };
  },
  methods: {
    getStatistics() {
      const options = {};
      finance.statistics(options).then(res => {
        if (res.code == 1) {
          this.totalCount = res.data.total_count;
        }
      });
    },
    screen() {
      this.search = true;
    },
    hideSystemPopup() {
      this.search = false;
    },
    handleCurrentChange(val) {
      this.pages = val;
      this.getList();
    },
    searchs() {
      this.getList();
    },
    getList() {
      this.showNodataTip = false;
      let options;
      if (this.time == "" || this.time == null) {
        options = {
          page: this.pages,
          mobile: this.userMobile,
          start_time: "",
          end_time: "",
          status: this.statusType
        };
      } else {
        options = {
          page: this.pages,
          mobile: this.userMobile,
          start_time: this.time[0],
          end_time: this.time[1],
          status: this.statusType
        };
      }
      finance.getCash(options).then(res => {
        if (res.code == 1) {
          this.search = false;
          this.listData = res.data.list;
          this.totalnum = res.data.total_nums;
          if (!res.data.total_nums) {
            this.showNodataTip = true;
          }
        }
      });
    },
    adopt(outsns) {
      this.$confirm("此操作将通过该账户的提现, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          const options = {
            outsn: outsns,
            type: 1
          };
          finance.doExamine(options).then(res => {
            if (res.code == 1) {
              this.$message({
                showClose: true,
                message: "通过成功！",
                type: "success"
              });
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    refuse(outsns) {
      this.$prompt("请输入拒绝理由", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
      })
        .then(({ value }) => {
          if (value == null || value == "") {
            this.$message({
              showClose: true,
              message: "请填写拒绝理由!",
              type: "error"
            });
            return false;
          }
          const options = {
            type: 0,
            outsn: outsns,
            message: value
          };
          finance.doExamine(options).then(res => {
            if (res.code == 1) {
              this.$message({
                showClose: true,
                message: "拒绝成功！",
                type: "success"
              });
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入"
          });
        });
    }
  },
  mounted() {
    this.getList();
    this.getStatistics();
  },
  filters: {
    times(value) {
      var time = new Date(value * 1000);
      var month =
        time.getMonth() + 1 > 9
          ? time.getMonth() + 1
          : "0" + (time.getMonth() + 1);
      var data = time.getDate() > 9 ? time.getDate() : "0" + time.getDate();
      var hour = time.getHours() > 9 ? time.getHours() : "0" + time.getHours();
      var minutes =
        time.getMinutes() > 9 ? time.getMinutes() : "0" + time.getMinutes();
      var second =
        time.getSeconds() > 9 ? time.getSeconds() : "0" + time.getSeconds();
      var times =
        time.getFullYear() +
        "-" +
        month +
        "-" +
        data +
        " " +
        hour +
        ":" +
        minutes +
        ":" +
        second;
      return times;
    }
  }
};
</script>

<style>
</style>
